package com.myproject.thread;

import org.junit.Test;

public class WaitNotify {

    private static Object obj = new Object();
    private static int count = 0;

    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    System.out.println("t1 get lock,count is "+count);
                    count++;
                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("t1 end,count is "+count);
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    System.out.println("t2 get lock,count is "+count);
                    count++;
                    obj.notify();
                    System.out.println("t2 end,count is "+count);
                }
            }
        });
        t1.start();
        Thread.sleep(100);
        t2.start();

    }






}
